<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2022/7/22 0022
 * Time: 15:10
 */

namespace framework\library;

use ArrayAccess;
class Config implements ArrayAccess
{
    protected $config = [];

    public function __construct()
    {

    }

    public function load($file)
    {
        $fileInfo = pathinfo($file);
        $filename = strtolower($fileInfo['filename']);
        $this->config[$filename] = include $file;
        return $this->config;
    }

    // config::get("app.deny_module_list.");
    public function get($name)
    {
        if (empty($name)) {
            return $this->config;
        }

        $configData = [];
        if ($name && false !== strpos($name, ".")) {
            // 判断带几个.
            $config = trim(explode(".", $name), ".");
            foreach (array_reverse($config) as $key => $value) {
                $configData = $this->config[$value];
            }

        } else {
            $configData = $this->config[$name];
        }

        return $configData;
    }

    // 移除配置项
    public function offsetUnset($offset)
    {

    }

    // 设置配置项
    public function offsetSet($offset, $value)
    {

    }

    public function offsetGet($offset)
    {
        return $this->get($offset);
    }

    public function offsetExists($offset)
    {
        return isset($this->config[$offset]) ? true : false;
    }

}